//
//  SAStatisticsSaleCell.m
//  saasRetail
//
//  Created by mac on 2022/7/22.
//

#import "SAStatisticsSaleCell.h"
#import "SAProductSalesVolumeModel.h"

@interface SAStatisticsSaleCell ()

@property (nonatomic, strong) UIImageView *imageV;
@property (nonatomic, strong) UIView *line;
@property (nonatomic, strong) UILabel *shopNameLab;
@property (nonatomic, strong) UILabel *sizeColourLab;
@property (nonatomic, strong) UILabel *codeLab;

@property (nonatomic, strong) UILabel *countLab;
@property (nonatomic, strong) UILabel *retailPriceLab;
@property (nonatomic, strong) UILabel *costLab;


@end

@implementation SAStatisticsSaleCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        self.selectionStyle = UITableViewCellSelectionStyleNone;
        [self initUI];
    }
    return self;
}

-(void)refreshWithModel:(SAProductSalesVolumeModel *)model AndType:(NSString *)type {
    
    NSString *newUrl = [[model.img componentsSeparatedByString:@","][0] stringByReplacingOccurrencesOfString:@"?x-oss-process=style/thumbnail" withString:@""];
    NSString *imageUrl = [NSString stringWithFormat:@"%@?x-oss-process=image/resize,l_100",newUrl];
    [self.imageV sd_setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@"shop_placeholderImg"]];
    self.shopNameLab.text = model.productName;
    
    if ([type isEqualToString:@"1"]) {
        self.sizeColourLab.text = [NSString stringWithFormat:@"%@,%@",model.colorName,model.sizeName];
    }else {
        self.sizeColourLab.text = @"";
    }
    
    self.codeLab.text = model.productCode;
    
    self.countLab.text = [NSString stringWithFormat:@"实销数:%@",model.salesCount];
    self.retailPriceLab.text = [NSString stringWithFormat:@"实销额:%0.2f",[model.salesAmount doubleValue]/100.f];
    self.costLab.text = [NSString stringWithFormat:@"毛利:%0.2f",[model.profit doubleValue]/100.f];
    
    SAUserInfo *userInfo = [SAValueManger shareInStance].userInfo;
    if (userInfo.userType != 1) {
        self.costLab.text = @"毛利:******";
    }
}

-(void)clickedImageV {
    !self.showImageBlock ?: self.showImageBlock();
}

#pragma mark - initUI
-(void)initUI {

    [self.contentView addSubview:self.imageV];
    [self.contentView addSubview:self.shopNameLab];
    [self.contentView addSubview:self.sizeColourLab];
    [self.contentView addSubview:self.codeLab];
    [self.contentView addSubview:self.countLab];
    [self.contentView addSubview:self.retailPriceLab];
    [self.contentView addSubview:self.costLab];
    [self.contentView addSubview:self.line];
    
}


#pragma mark - lazy
-(UIImageView *)imageV {
    if (!_imageV) {
        _imageV = [[UIImageView alloc] initWithFrame:SARectMake(26, 6, 53, 59)];
        UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickedImageV)];
        _imageV.contentMode = UIViewContentModeScaleAspectFit;
        _imageV.clipsToBounds = YES;
        [_imageV setContentScaleFactor:[[UIScreen mainScreen] scale]];
        _imageV.userInteractionEnabled = YES;
        [_imageV addGestureRecognizer:tap];
    }
    return _imageV;
}

-(UIView *)line {
    if (!_line) {
        _line = [[UIView alloc] initWithFrame:SARectMake(0, 70, 375, 1)];
        _line.backgroundColor = kLineColor;
    }
    return _line;
}

-(UILabel *)shopNameLab {
    if (!_shopNameLab) {
        _shopNameLab = [[UILabel alloc] initWithFrame:SARectMake(85, 5, 140, 20)];
        _shopNameLab.textColor = [UIColor blackColor];
        _shopNameLab.font = kFont(15);
        _shopNameLab.adjustsFontSizeToFitWidth = YES;
        _shopNameLab.minimumScaleFactor = 0.8;
    }
    return _shopNameLab;
}

-(UILabel *)sizeColourLab {
    if (!_sizeColourLab) {
        _sizeColourLab = [[UILabel alloc] initWithFrame:SARectMake(85, 25, 140, 20)];
        _sizeColourLab.textColor = kLightgGrayColor;
        _sizeColourLab.font = kFont(15);
        _sizeColourLab.adjustsFontSizeToFitWidth = YES;
        _sizeColourLab.minimumScaleFactor = 0.8;
    }
    return _sizeColourLab;
}

-(UILabel *)codeLab {
    if (!_codeLab) {
        _codeLab = [[UILabel alloc] initWithFrame:SARectMake(85, 45, 140, 20)];
        _codeLab.textColor = kLightgGrayColor;
        _codeLab.font = kFont(15);
        _codeLab.adjustsFontSizeToFitWidth = YES;
        _codeLab.minimumScaleFactor = 0.8;
    }
    return _codeLab;
}

-(UILabel *)countLab {
    if (!_countLab) {
        _countLab = [[UILabel alloc] initWithFrame:SARectMake(230, 5, 145, 20)];
        _countLab.textAlignment = NSTextAlignmentLeft;
        _countLab.textColor = kLightgGrayColor;
        _countLab.font = kFont(15);
        _countLab.adjustsFontSizeToFitWidth = YES;
        _countLab.minimumScaleFactor = 0.8;
    }
    return _countLab;
}

-(UILabel *)retailPriceLab {
    if (!_retailPriceLab) {
        _retailPriceLab = [[UILabel alloc] initWithFrame:SARectMake(230, 25, 145, 20)];
        _retailPriceLab.textColor = kLightgGrayColor;
        _retailPriceLab.textAlignment = NSTextAlignmentLeft;
        _retailPriceLab.font = kFont(15);
        _retailPriceLab.adjustsFontSizeToFitWidth = YES;
        _retailPriceLab.minimumScaleFactor = 0.8;
    }
    return _retailPriceLab;
}

-(UILabel *)costLab {
    if (!_costLab) {
        _costLab = [[UILabel alloc] initWithFrame:SARectMake(230, 45, 145, 20)];
        _costLab.textColor = kLightgGrayColor;
        _costLab.textAlignment = NSTextAlignmentLeft;
        _costLab.font = kFont(15);
        _costLab.adjustsFontSizeToFitWidth = YES;
        _costLab.minimumScaleFactor = 0.8;
    }
    return _costLab;
}

@end
